package com.fuyin.commons.configuration;

import org.springframework.context.annotation.Configuration;

/**
 * @author yuanxilan (yuanxilan@keep.com)
 * @Description
 * @date 2021年10月27日 11:11 上午
 * @since
 */
@Configuration// 配置类
public class CorsConfig {
//    @Bean
//    public WebMvcConfigurer corsConfigurer() {
//        return new WebMvcConfigurer() {
//            @Override
//            public void addCorsMappings(CorsRegistry registry) {
//                registry.addMapping("/**")// 对所有请求路径
//                        .allowedOriginPatterns("*")// 允许所有域名
//                        .allowCredentials(true)// 允许 cookie 等凭证
//                        .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")// 允许所有方法
//                        .allowedHeaders("*")
//                        .exposedHeaders("access-control-allow-headers",
//                                "access-control-allow-methods",
//                                "access-control-allow-origin",
//                                "access-control-max-age",
//                                "X-Frame-Options")
//                        .maxAge(3600);
//            }
//        };
//    }

//    @Bean
//    public CorsFilter corsFilter() {
//        CorsConfiguration config = new CorsConfiguration();
//        //允许所有域名进行跨域调用
//        config.addAllowedOriginPattern("*");
//        //允许跨越发送cookie
//        config.setAllowCredentials(true);
//        //放行全部原始头信息
//        config.addAllowedHeader("*");
//        //允许所有请求方法跨域调用
//        config.addAllowedMethod("*");
////        config.addExposedHeader("access-control-allow-headers");
////        config.addExposedHeader("access-control-allow-methods");
////        config.addExposedHeader("access-control-allow-origin");
////        config.addExposedHeader("access-control-max-age");
////        config.addExposedHeader("X-Frame-Options");
//        config.addExposedHeader("*");
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        source.registerCorsConfiguration("/**", config);
//        return new CorsFilter(source);
//    }
}

